home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / gprim / sphere / spherecreate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-20  |  2.7 KB  |  96 lines

  1. #include <math.h>
  2. #include "geom.h"
  3. #include "geomclass.h"
  4. #include "transform.h"
  5. #include "hpoint3.h"
  6. #include "sphereP.h"
  7. #include "bezier.h"
  8.  
  9. static float ctrlPnts[] = {
  10.   1, 0, 0, 1,    1, 0, 1, 1,     0, 0, 2, 2,
  11.   1, 1, 0, 1,    1, 1, 1, 1,    0, 0, 2, 2,
  12.   0, 2, 0, 2,    0, 2, 2, 2,    0, 0, 4, 4
  13. };
  14.  
  15. static Transform reflections[] = {
  16.   {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}},
  17.   {{1, 0, 0, 0}, {0,-1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}},
  18.   {{-1,0, 0, 0}, {0,-1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}},
  19.   {{-1,0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}},
  20.   {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, -1, 0}, {0, 0, 0, 1}},
  21.   {{1, 0, 0, 0}, {0,-1, 0, 0}, {0, 0, -1, 0}, {0, 0, 0, 1}},
  22.   {{-1,0, 0, 0}, {0,-1, 0, 0}, {0, 0, -1, 0}, {0, 0, 0, 1}},
  23.   {{-1,0, 0, 0}, {0, 1, 0, 0}, {0, 0, -1, 0}, {0, 0, 0, 1}}
  24. };
  25.  
  26. Sphere *SphereCreate(exist, classp, a_list) 
  27. Geom *exist;
  28. GeomClass *classp;
  29. va_list a_list;
  30. {
  31.   Geom *quadrant;
  32.   Geom *unitsphere;
  33.   Sphere *sphere;
  34.   int space, nencompass_points = 0;
  35.   int attr;
  36.   Transform T, *axis = NULL;
  37.   HPoint3 *encompass_points = NULL;
  38.  
  39.   if (exist == NULL) {
  40.     sphere = OOGLNewE(Sphere, "SphereCreate:  new Sphere");
  41.     GGeomInit(sphere, classp, SPHEREMAGIC, NULL);
  42.     sphere->instflag = 0;
  43.     sphere->geomhandle = NULL;
  44.     sphere->geom = NULL;
  45.     sphere->tlisthandle = NULL;
  46.     sphere->tlist = NULL;
  47.     sphere->axishandle = NULL;
  48.     sphere->radius = 1.0;
  49.     sphere->space = TM_EUCLIDEAN;
  50.     HPt3From(&(sphere->center), 0.0, 0.0, 0.0, 1.0);
  51.   } else sphere = (Sphere *)exist;
  52.  
  53.   while (attr = va_arg (a_list, int)) switch (attr) {
  54.   case CR_FLAG:
  55.     sphere->instflag = va_arg(a_list, int );
  56.     break;
  57.   case CR_CENTER:
  58.     sphere->center = *va_arg(a_list, HPoint3 *);
  59.     break;
  60.   case CR_RADIUS:
  61.     sphere->radius = va_arg(a_list, double);
  62.     break;
  63.   case CR_SPACE:
  64.     sphere->space = va_arg(a_list, int);
  65.     break;
  66.   case CR_ENCOMPASS_POINTS:
  67.     encompass_points = va_arg(a_list, HPoint3 *);
  68.     break;
  69.   case CR_NENCOMPASS_POINTS:
  70.     nencompass_points = va_arg(a_list, int);
  71.     break;
  72.   case CR_AXIS:
  73.     axis = va_arg(a_list, Transform *);
  74.     break;
  75.   default:
  76.     OOGLError (0, "SphereCreate: Undefined option: %d",attr);
  77.     return NULL;
  78.   }
  79.   HPt3Normalize(&(sphere->center), &(sphere->center));
  80.  
  81.   quadrant = GeomCCreate(NULL, BezierMethods(), 
  82.              CR_DEGU, 2, CR_DEGV, 2, 
  83.              CR_DIM, 4, CR_POINT, ctrlPnts, CR_END);
  84.   unitsphere = GeomCreate("tlist", CR_NELEM, 8, CR_ELEM, reflections,
  85.               CR_END);
  86.   sphere->geom = GeomCCreate(NULL, InstMethods(), CR_GEOM, quadrant, CR_TLIST,
  87.                 unitsphere, CR_END);
  88.  
  89.   SphereSwitchSpace(sphere, sphere->space);
  90.   if (nencompass_points && encompass_points != NULL) 
  91.     SphereEncompassHPt3N(sphere, encompass_points, nencompass_points, 
  92.              (axis == NULL) ? TM_IDENTITY : *axis);
  93.   return sphere;
  94. }
  95.  
  96.